package com.lxh.lxhcrm.controller.productManagement;

import com.github.pagehelper.Page;
import com.github.pagehelper.PageHelper;
import com.lxh.lxhcrm.model.pojos.DeliveryPlan;
import com.lxh.lxhcrm.model.pojos.InWare;
import com.lxh.lxhcrm.model.pojos.OutWare;
import com.lxh.lxhcrm.model.service.WareService;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.annotation.Resource;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

@RestController
@RequestMapping("/ware")
public class WareController {
    @Resource
    WareService wareService;
    /*
     * 查询
     * */
    //出库表查询
    @RequestMapping("/out-list")
    public Map<String,Object> findOutWare(Integer currPage, Integer pageSize,String searchText,Integer selectModel,Integer judge){
        Page<Object> page= PageHelper.startPage(currPage,pageSize);
        Map<String,Object> map=new HashMap<>();
        List<OutWare> wares=wareService.findOutWare(searchText,selectModel,judge);
        map.put("data",wares);
        map.put("total",page.getTotal());
        return map;
    }
    //无分页查询出库
    @RequestMapping("/all-out")
    public List<OutWare> allOutWare(){
        List<OutWare> outWares=wareService.allOutWare();
        return outWares;
    }
    //入库表查询
    @RequestMapping("/in-list")
    public Map<String,Object> findInWare(Integer currPage, Integer pageSize,String searchText,Integer selectModel,Integer judge){
        Page<Object> page= PageHelper.startPage(currPage,pageSize);
        Map<String,Object> map=new HashMap<>();
        List<InWare> wares=wareService.findInWare(searchText,selectModel,judge);
        map.put("data",wares);
        map.put("total",page.getTotal());
        return map;
    }
    //无分页查询入库
    @RequestMapping("/all-in")
    public List<InWare> allInWare(){
        List<InWare> inWares=wareService.allInWare();
        return inWares;
    }
    //查询所有交付计划，入库所需
    @RequestMapping("/delivery-plan")
    public Map<String,Object> findDeliveryPlan(Integer currPage, Integer pageSize){
        Page<Object> page= PageHelper.startPage(currPage,pageSize);
        Map<String,Object> map=new HashMap<>();
        List<DeliveryPlan> deliveryPlans=wareService.findDeliveryPlan();
        map.put("data",deliveryPlans);
        map.put("total",page.getTotal());
        return map;
    }
    //查询此用户是否具备审核功能
    @RequestMapping("/findDuty")
    public boolean findDuty(Integer empId){
        return wareService.findDuty(empId);
    }
    /*
     * 新增
     * */
    //添加出库表
    @RequestMapping("/add_out")
    public void addOutWare(@RequestBody OutWare outWare) {
        wareService.addOutWare(outWare);
    }
    //添加入库表
    @RequestMapping("/add_in")
    public void addInWare(@RequestBody InWare inWare){wareService.addInWare(inWare);}
    /*
     * 修改
     * */
    //修改出库表状态
    @RequestMapping("/change-outstate")
    public void changeOutState(Integer judge,Integer outId){wareService.changeOutState(judge,outId);}
    //修改入库表状态
    @RequestMapping("/change-instate")
    public void changeInState(Integer judge,Integer inId){wareService.changeInState(judge,inId);}
    //出入库完成,修改产品数量
    @RequestMapping("/change-num")
    public void changeProNum(Integer proDetailId,Integer wareNum,Integer proNum){wareService.changeProNum(proDetailId,wareNum,proNum);}
    //入库完成,修改交付计划状态
    @RequestMapping("/change-deliveryPlan")
    public void changeDeliveryPlan(Integer isOut,Integer deliveryPlanId){wareService.changeDeliveryPlan(isOut,deliveryPlanId);}
}
